//
//  XBTabBarController.m
//  shiLeChlorella
//
//  Created by HX on 2017/7/20.
//  Copyright © 2017年 TXB. All rights reserved.
//

#import "XBTabBarController.h"

#import "XBNavigationController.h"
#import "XBHomeViewController.h"
#import "XBMessageViewController.h"
#import "XBWalletViewController.h" 

#import "ZZTabBar.h"

@interface XBTabBarController ()<ZZTabBarDelegate>
@property (nonatomic, strong) ZZTabBar *customTabBar;
@end

@implementation XBTabBarController


//- (void)viewWillAppear:(BOOL)animated
//{
//     [super viewWillAppear:animated];
//
//     for (UIView *child in self.tabBar.subviews) {
//          if ([child isKindOfClass:[UIControl class]]) {
//               [child removeFromSuperview];
//          }
//     }
//}

- (void)viewDidLoad {

    [super viewDidLoad];
          // 初始化tabbar

//     [self setupTabbar];
          // 初始化所有的子控制器
     [self setupAllChildViewControllers];


}

- (void)setupTabbar
{
     self.customTabBar = [[ZZTabBar alloc] init];
     self.customTabBar.frame = self.tabBar.bounds; 
     self.customTabBar.delegate = self; 
     [self.tabBar addSubview:self.customTabBar];

}



- (void)setupAllChildViewControllers
{
     XBHomeViewController *home = [[XBHomeViewController alloc] init];
            
     [self setupChildViewController:home title:@"雷达" imageName:@"tabbar_home_normal" selectedImageName:@"tabbar_home_selected"];


     XBMessageViewController *categorys = [[XBMessageViewController alloc] init];
     [self setupChildViewController:categorys title:@"转账" imageName:@"tabbar_message_normal" selectedImageName:@"tabbar_message_selected"];


//     XBSetViewController *found = [[XBSetViewController alloc] init];
//     [self setupChildViewController:found title:@"购汇" imageName:@"tabbar_setting_normal" selectedImageName:@"tabbar_setting_selected"];

     XBWalletViewController *wallet = [[XBWalletViewController alloc] init];
     [self setupChildViewController:wallet title:@"钱包" imageName:@"tabbar_setting_normal" selectedImageName:@"tabbar_setting_selected"];


}


#pragma mark - tabbar的代理方法
- (void)tabBar:(ZZTabBar *)tabBar didSelectedButtonFrom:(NSInteger)from to:(NSInteger)to
{
     self.selectedIndex = to;

}


- (void)setupChildViewController:(UIViewController *)childVc title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName
{ 
     childVc.title = title;
//     childVc.tabBarItem.badgeValue = @"111";
     childVc.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -3);
     childVc.tabBarItem.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);
     childVc.tabBarItem.image = [UIImage imageNamed:imageName] ;
     childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

     XBNavigationController *nav = [[XBNavigationController alloc] initWithRootViewController:childVc];

     [self addChildViewController:nav];

//     [self.customTabBar addTabBarButtonWithItem:childVc.tabBarItem];

     
}



@end
